package br.com.lavitstudio.game;

import java.util.Random;

public class level_Plants {
	private Block[][] block;
	
	public level_Plants(Block[][] block) {
		this.block = block;
	}
	
	public void generateLevel() {
		// Grama
		for(int y=0;y<block.length;y++) {
			for(int x=0; x<block[0].length; x++) {
				if(block[x][y].id == Tile.block.get("earth") && block[x][y-1].id == Tile.block.get("air")) {
					block[x][y].id = Tile.block.get("grass");
				}
			}
		}
		
		// Arvores
		for(int y=0;y<block.length;y++) {
			for(int x=0; x<block[0].length; x++) {
				try {
					if(block[x][y + 1].id == Tile.block.get("grass") && block[x][y].id == Tile.block.get("air") && block[x][y-1].id == Tile.block.get("air") /* Wood 1bloco de distancia */ && block[x - 1][y].id != Tile.block.get("wood") && block[x + 1][y].id != Tile.block.get("wood")) {
						if(new Random().nextInt(100) < 10) {
							int rnd = new Random().nextInt(6) + 4;
							for(int n=0;n<rnd;n++) {
								block[x][y-n].id = Tile.block.get("wood");
							}
							block[x][y-rnd].id = Tile.block.get("leaves");
							
							for(int l = 1; l < (new Random().nextInt(3) + 2); l++){
								block[x][y-(rnd + l)].id = Tile.block.get("leaves");
							}
							
							for(int j = 1; j < (new Random().nextInt(3)+3); j++){
								for(int l = 1; l < (new Random().nextInt(5) + 2); l++){
									block[x-j][y-rnd].id = Tile.block.get("leaves");
								}
	
								for(int l = 1; l < (new Random().nextInt(5) + 2); l++){
									block[x+j][y-rnd].id = Tile.block.get("leaves");
								}
	
								for(int l = 1; l < (new Random().nextInt(5) + 2); l++){
									block[x-j][y-(rnd - l)].id = Tile.block.get("leaves");
								}
	
								for(int l = 1; l < (new Random().nextInt(5) + 2); l++){
									block[x+j][y-(rnd - l)].id = Tile.block.get("leaves");
								}
	
								for(int l = 1; l < (new Random().nextInt(5) + 2); l++){
									block[x-j][y-((rnd - l) - 1)].id = Tile.block.get("leaves");
								}
	
								for(int l = 1; l < (new Random().nextInt(5) + 2); l++){
									block[x+j][y-((rnd - l) - 1)].id = Tile.block.get("leaves");
								}
							}
							
						}
					}
				} catch (Exception e){ }
			}
		}
	}
}
